//
//  Sqlite3ViewController.swift
//  CHSimpleUI
//
//  Created by cyptt on 2022/8/19.
//

import UIKit

class Sqlite3ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }


    
    @IBAction func createCh(_ sender: UIButton) {
        
        if (CHSqlite3.shareInstance().createDataBase("chdbtest1.sqlite") == true){
            print("开启数据库成功")
        }else{
            print("开启数据库失败")
        }
    }
    
    @IBAction func openCh(_ sender: UIButton) {
    }
    
    @IBAction func createTab(_ sender: UIButton) {
        CHSqlite3.shareInstance().createTable("fmdbtab", paramSql: "name text, age integer, sex text")
    }
    
    @IBAction func insertch(_ sender: UIButton) {
        
        let map:[String:Any] = ["name":"zs","age":313,"sex":"1"]
        CHSqlite3.shareInstance().insertTable("fmdbtab", paramDic: map)
    }
    
    
    @IBAction func queryCh(_ sender: UIButton) {
        
        let  array:[Any]? = CHSqlite3.shareInstance().queryAll("fmdbtab");
        print("array---",array)
    }
    @IBAction func queryIfCh(_ sender: UIButton) {
        
        let SQL:String = "SELECT * FROM fmdbtab where name = 'zs'"
        let array:[Any]? = CHSqlite3.shareInstance().queryConditionSql(SQL)
        print("arrar----",array)
    }
    @IBAction func updateCh(_ sender: UIButton) {
        let SQL:String = "update fmdbtab set name = 'lsi1' where id = 1"
        CHSqlite3.shareInstance().updateSql(SQL)
    }
    
    @IBAction func cancelCh(_ sender: UIButton) {
        let SQL:String = "delete from fmdbtab  where id = 2"
        CHSqlite3.shareInstance().deleteSql(SQL)
    }
    
    @IBAction func closeCh(_ sender: UIButton) {
        
        CHSqlite3.shareInstance().close()
    }
    

}
